from django.db import models

from wagtail.core.models import Page
#from wagtail.images.models import Image
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel


class HomePage(Page):
    '''
    pass
    '''
    body = RichTextField(blank=True)

    def get_context(self, request):
        # Update context to include only published posts, ordered by reverse-chron
        context = super().get_context(request)
        page = Page.objects.get(title="博客列表")
        blogpages = page.get_children().live().order_by('-first_published_at')[:3]
        # tags = Tag.objects.all().order_by('name')
        #wallpapers = Image.objects.filter(tags__name="美丽1").order_by('-created_at')[:3]
        context['blogpages'] = blogpages
        #context['wallpapers'] = wallpapers
        # context['tags'] = tags
        return context

    content_panels = Page.content_panels + [
        FieldPanel('body', classname="full"),
    ]